/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xrkol.sharelib.dao.GuardianDao;
import com.xrkol.sharelib.entity.User;
import com.xrkol.sharelib.entity.Guardian;
import com.xrkol.sharelib.entity.Student;

/**
 * @author peng.xia
 *
 */
@Repository
public class GuardianDaoImpl extends BaseDaoImpl<Guardian,String> implements GuardianDao{

    @Override
    public List<Guardian> findByStudent(Student student) {
        String queryString="from Guardian g where g.student=?";
        return executeQueryWithoutPaging(queryString, student);
    }

    @Override
    public Guardian findByStudentAndGuardian(User guardian, Student student) {
        String queryString="from Guardian g where g.student=? and g.adult=?";
        List<Guardian> guardianships=executeQueryWithoutPaging(queryString, student,guardian);
        return guardianships.size()>0?guardianships.get(0):null;
    }

    @Override
    public List<Guardian> findByUserId(String userId) {
        String queryString="from Guardian g where g.adult.userId = ?";
        return executeQueryWithoutPaging(queryString, userId);
    }

    @Override
    public List<Guardian> findByAdult(User adult) {
        String queryString="from Guardian g where g.adult = ?";
        return executeQueryWithoutPaging(queryString, adult);
    }

}
